package it.webrules.deploymanager.core.dy.repos;

import it.webrules.deploymanager.core.config.ConfigurationService;
import it.webrules.deploymanager.core.dy.repos.nexus.NexusConnection;
import it.webrules.xsd.dmc.config.v1.Nexus;
import it.webrules.xsd.dmc.config.v1.WebappConfig.Repository;

/**
 * 
 * Manage the build system (now only jenkins)
 * 
 * @author dometec
 *
 */
public class ReposytoryService {

	private final ConfigurationService configurationService;

	public ReposytoryService(ConfigurationService configurationService) {
		this.configurationService = configurationService;
	}

	public RepositoryConnection getRepositoryConnection() throws RepositoryException {

		RepositoryConnection connection = null;

		Repository repository = configurationService.getRepositoryElement();
		if (repository != null) {

			Nexus nexus = repository.getNexus();
			if (nexus != null) {
				connection = new NexusConnection(nexus);
			} else {
				throw new RepositoryException("Not repository system selected ()!");
			}

		}

		return connection;

	}
}
